def is_valid_sequence(sequence):
    stack = []
    a = ['(', '[', '{', '<']
    b = [')', ']', '}', '>']
    c = dict(zip(b,a))
    
    for bracket in sequence:
        if bracket in a:
            stack.append(bracket)
        elif bracket in b:
            if not stack or stack[-1] != c[bracket]:
                return False
            stack.pop()
    
    return len(stack) == 0

sequence = input("Введите скобочную последовательность: ")
print(is_valid_sequence(sequence))
